package similan.br18.domain;

import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

import similan.br18.util.ContactComparator;

public class MemberInfo implements Contact, Comparable<Contact> {

	private static final long serialVersionUID = -8923385177921657847L;
	private long id;
	private String name;
	private String imagePath;
	private String title;
	private String email;
	private String company;
	private String address;

	public MemberInfo() {
		super();
	}

	public MemberInfo(String name, String title, String email, String company,
			String address) {
		setName(name);
		setTitle(title);
		setEmail(email);
		setCompany(company);
		setAddress(address);
	}

	@Override
	public String getImagePath() {
		return imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	@Override
	public String getFullName() {
		return name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String getDetailInfo() {
		return "some detailed info";
	}

	@Override
	public ContactType getContactType() {
		return ContactType.Member;
	}

	@Override
	public Set<? extends Contact> getContacts() {
		Set<MemberInfo> users = new TreeSet<MemberInfo>(ContactComparator.INSTANCE);
		int size = new Random().nextInt(20) + 20;
		for (int i = 0; i < size; i++) {
			MemberInfo user = new MemberInfo();
			user.setId(i);
			user.setTitle("Developer " + i);
			user.setImagePath("icon_no_photo_40x40.png");
			user.setAddress("USA_" + i);
			user.setCompany("Business Reach Inc_" + i);
			user.setEmail(i + "user@businessreach-inc.com");
			char randomChar = (char) ((new Random().nextInt(50)) + ((int) '0'));
			user.setName(randomChar + "_" + getFullName() + "_contact" + i);
			users.add(user);
		}
		
		return users;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Contact o) {
		return this.getFullName().compareTo(o.getFullName());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see similan.br18.domain.Contact#getFirstLetter()
	 */
	@Override
	public Character getFirstLetter() {
		int asciiCode = (int) getFullName().charAt(0);

		if ((asciiCode >= ((int) 'A') && asciiCode <= ((int) 'Z'))
				|| (asciiCode >= ((int) 'a') && asciiCode <= ((int) 'z'))) {
			return Character.toTitleCase(getFullName().charAt(0));
		} else {
			return Character.valueOf(NONENGLISH_CHARS_FIRST_LETTER);
		}
	}

	public long getId() {
		return this.id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getCompany() {
		return this.company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
}
